﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace BTCairo
{
    public class BasicLine : BasicShape
    {
        int x1, y1, x2, y2;
        public BasicLine(CommonGraphics _comGra, int _x1, int _y1, int _x2, int _y2)
        {
            CommonGraphics = _comGra;
            InfoGraphic = _comGra.MyInfoGraphic;
            x1 = _x1;
            y1 = _y1;
            x2 = _x2;
            y2 = _y2;
        }

        public override void Draw()
        {
            CommonGraphics.DrawLine(x1, y1, x2, y2);
        }

        public override string ToString()
        {
            string rgb = "rgb(" + InfoGraphic.lineRed + "," + InfoGraphic.lineGreen + "," + InfoGraphic.lineBlue + ")";
            string strSVG = "<line x1=\"" + x1 + "\" y1 = \"" +  y1 + "\" x2=\"" + x2 + "\" y2=\"" + y2 + "\" style=\"stroke:" + rgb + ";stroke-width:" + InfoGraphic.width + "\" />" + "\n";
            //<line x1="0" y1="0" x2="200" y2="200"
  //style="stroke:rgb(255,0,0);stroke-width:2"/>
            return strSVG;
        }

        public override void ParseXmlElement(System.Xml.XmlDocument doc, System.Xml.XmlElement root)
        {
            XmlElement node = doc.CreateElement("line");
            node.SetAttribute("x1", x1.ToString());
            node.SetAttribute("y1", y1.ToString());
            node.SetAttribute("x2", x2.ToString());
            node.SetAttribute("y1", y1.ToString());
            string rgb = "rgb(" + InfoGraphic.lineRed + "," + InfoGraphic.lineGreen + "," + InfoGraphic.lineBlue + ")";
            string style = "stroke:" + rgb + ";stroke-width:" + InfoGraphic.width;
            node.SetAttribute("style", style);
            root.AppendChild(node);
        }
    }
}
